﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _07_WebHost.Host
{
    public static class UseExtensions
    {
        public static void Use(this IApplicationBuilder builder,Func<HttpContext, Func<Task>, Task> middleware)
        {
            builder.Use((next) =>
            {
                return async c =>
                {
                    await middleware(c, () => next(c));
                };
            });
        }

        public static void Use(this IApplicationBuilder builder, Func<HttpContext, RequestDelegate, Task> middleware)
        {
            builder.Use((next) =>
            {
                return async c =>
                {
                    await middleware(c, next);
                };
            });
        }

        public static void Run(this IApplicationBuilder builder, RequestDelegate handler)
        {
            builder.Use((next) =>
            {
                return async c =>
                {
                    await handler(c);
                };
            });
        }
    }
}
